import { Content } from "./content";

// 聊天消息接口
export interface ChatMessage {
  role: 'user' | 'assistant' | 'system';
  content: string;
  createdAt: string;
}

// 聊天请求接口
export interface ChatRequest {
  chatId?: string;
  stream?: boolean;
  detail?: boolean;
  responseChatItemId?: string;
  variables?: Record<string, any>; // 支持复杂数据结构，包括学生画像和推荐数据
  messages: ChatMessage[];
}

// 聊天响应接口
export interface ChatResponse {
  id: string;
  model: string;
  usage: {
    prompt_tokens: number;
    completion_tokens: number;
    total_tokens: number;
  };
  choices: Array<{
    message: {
      role: string;
      content: string;
    };
    finish_reason: string;
    index: number;
    type?: string;
  }>;
    responseData?: unknown[];
  newVariables?: Record<string, any>;
}

// 聊天会话接口
export interface ChatSession {
  id: string;
  chatId: string;
  title: string;
  userId: string;
  agentId?: string;
  contentId?: string;
  createdAt: string;
  updatedAt: string;
  messageCount?: number;
  lastMessage?: string;
  content?: Content;
  _count?: {
    messages: number;
  };
}

// 聊天会话详情接口
export interface ChatSessionDetail extends ChatSession {
  messages: ChatItem[];
  isNewSession?: boolean; // 标识是否为新建会话
}

// 聊天记录接口
export interface ChatItem {
  id: string;
  chatItemId: string;
  chatId: string;
  role: string;
  content: string;
  tokens?: number;
  createdAt: string;
}

// 聊天会话查询参数
export interface ChatSessionParams {
  page?: number;
  pageSize?: number;
  search?: string;
}

// 聊天会话创建参数
export interface CreateChatSessionRequest {
  title?: string;
  agentId?: string;
}

// 聊天会话更新参数
export interface UpdateChatSessionRequest {
  title?: string;
}

// API 响应类型
export interface ChatSessionListResponse {
  success: boolean;
  data: ChatSession[];
}

export interface ChatSessionPageResponse {
  success: boolean;
  data: ChatSession[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
  hasNextPage: boolean;
  hasPrevPage: boolean;
}

export interface ChatSessionDetailResponse {
  success: boolean;
  data: ChatSessionDetail;
}

export interface ChatSessionResponse {
  success: boolean;
  data: ChatSession;
}

export interface ChatCompletionResponse {
  success: boolean;
  data: ChatResponse & { chatId?: string };
}

export interface DeleteChatSessionResponse {
  success: boolean;
  message: string;
}

export interface ClearAllChatResponse {
  success: boolean;
  message: string;
  deletedCount: number;
  deletedMessagesCount: number;
}

// 删除聊天记录请求参数
export interface DeleteChatMessagesRequest {
  chatId: string;
  messageId?: string; // 消息ID（可选）
  messageContent?: string; // 消息内容（可选，用于查找消息）
  messageRole?: 'user' | 'assistant'; // 消息角色（可选）
  messageTimestamp?: string; // 消息时间戳（可选，用于精确匹配）
}

// 删除聊天记录响应
export interface DeleteChatMessagesResponse {
  success: boolean;
  deletedCount: number;
}




